import Vue from 'vue';
import Vuex from 'viex';

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: {}
	},
	mutations: {
		login(store, provider){
			state.hasLogin = true
			state.userInfo.uname = provider.uname
			state.userInfo.avatar = provider.avatar
			
			uni.setStorage({
				key: 'userInfo',
				data: provider
			})
		},
		logout(state){
			state.hasLogin = false,
			state.userInfo = {},
			
			uni.removeStorage({
				key: 'userInfo'
			})
		}
	}
})